package com.nariano.server.publisher;

import java.util.HashSet;
import java.util.Set;

public class ClientPublisherImpl implements ClientPublisher, ClientPublisherRegister {
	
	Set<ClientPublisherListener> listeners = new HashSet<ClientPublisherListener>();

	@Override
	public void endRound() {
		synchronized (listeners) {
			throw new UnsupportedOperationException("dont call me");
		}
		
	}

	@Override
	public void publish(Event event) {
		synchronized (listeners) {
			for (ClientPublisherListener l : listeners) {
				l.onEvent(event);
			}
		}
	}

	@Override
	public void startRound() {
		synchronized (listeners) {
	throw new UnsupportedOperationException("dont call me");
		}
	}
	
	public void add(ClientPublisherListener listener) {
		synchronized (listeners) {
			 	listeners.add(listener);
			}
	}

	public void remove(ClientPublisherListener listener) {
		synchronized (listeners) {
		 	listeners.remove(listener);
		}
	}
}
